package com.cw.lang.validator.config;

import javax.validation.Validation;
import javax.validation.Validator;

import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chenw
 * @version $$Id: ValidatorConfig.java, v 0.1 2018/9/19 下午6:06 chenw Exp $$
 */
@Configuration
public class ValidatorConfiguration {

    @Bean("allMethodValidationPostProcessor")
    public AllMethodValidationPostProcessor methodValidationPostProcessor() {
        return new AllMethodValidationPostProcessor();
    }

    @Bean
    public Validator validator() {
        // 设置failFast 立即失败模式
        return Validation.byProvider(HibernateValidator.class).configure().failFast(true).buildValidatorFactory()
            .getValidator();
    }

}
